package org.pentaho.di.ui.trans.steps.shentong.oss.client;

public class ResponseBody<T extends AbstractXMLData> {
	private int statusCode;
	private T data;
	private String message;

	private ResponseBody(int statusCode, T data) {
		this.data = data;
		this.statusCode = statusCode;
	}

	private ResponseBody() {
	}

	public static ResponseBody success(int statusCode, String message) {
		ResponseBody body = new ResponseBody();
		body.data = new CommonResult();
		body.statusCode = statusCode;
		body.message = message;
		return body;
	}

	public static <T extends AbstractXMLData> ResponseBody success(int statusCode, T data) {
		return new ResponseBody(statusCode, data);
	}

	public static ResponseBody error(Exception e) {
		ResponseBody body = new ResponseBody();
		body.data = new OssError();
		((OssError) body.data).setCode(e.getMessage());
		((OssError) body.data).setMessage(e.getMessage());
		return body;
	}

	public static <T extends AbstractXMLData> ResponseBody error(int statusCode, T data) {
		ResponseBody body = new ResponseBody();
		body.statusCode = statusCode;
		body.data = data;
		return body;
	}

	public String getMessage() {
		return this.message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return this.data;
	}

	public int getStatusCode() {
		return this.statusCode;
	}

	public String toString() {
		return "{statusCode: " + this.statusCode + ", data: " + this.data + ", message: '" + this.message + '\'' + '}';
	}
}
